package regexp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author DCSGO
 * @version 1.0
 * 正则表达式应用案例
 * 汉字字符 邮编 QQ号 手机号
 */
public class Regexp10 {
    //检验是否是汉字字符
    public static boolean isChineseCharacter(String input) {
        //Pattern pattern = Pattern.compile("^[\u4E00-\u9FFF]+$"); //汉字
        Pattern pattern = Pattern.compile("^[\u0391-\uffe5]+$");//包含中文字符
        Matcher matcher = pattern.matcher(input);
        return matcher.find();
    }

    //检验是否是邮政编码(1-9开头的一个六位数)
    public static boolean isPostalCode(String input) {
        Pattern pattern = Pattern.compile("^[1-9]\\d{5}$");
        Matcher matcher = pattern.matcher(input);
        return matcher.find();
    }

    //检验是否是QQ号码(1-9开头的一个5-10位数)
    public static boolean isQQNumber(String input) {
        Pattern pattern = Pattern.compile("^[1-9]\\d{4,9}$");
        Matcher matcher = pattern.matcher(input);
        return matcher.find();
    }

    //验证是否是手机号(必须以13,14,15,18 开头的11位数)
    public static boolean isTelNumber(String input) {
        Pattern pattern = Pattern.compile("^1[3|4|5|8]\\d{9}$");
        Matcher matcher = pattern.matcher(input);
        return matcher.find();
    }

    public static void main(String[] args) {
        System.out.println(isChineseCharacter("原神启动"));//true
        System.out.println(isChineseCharacter("原神启动!"));//false
        System.out.println(isChineseCharacter("原神，启动！"));//true

        System.out.println(isPostalCode("123456"));//true
        System.out.println(isPostalCode("023456"));//false
        System.out.println(isPostalCode("13456"));//false

        System.out.println(isQQNumber("2729766103"));//true
        System.out.println(isQQNumber("0729766103"));//false
        System.out.println(isQQNumber("12345"));//true
        System.out.println(isQQNumber("1234"));//false
        System.out.println(isQQNumber("12345678910"));//false

        System.out.println(isTelNumber("18472528622"));//true
        System.out.println(isTelNumber("12472528622"));//false
        System.out.println(isTelNumber("1847252862"));//false
        System.out.println(isTelNumber("181234567890"));//false
    }
}
